package com.yh.homestay.controller;


import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.UserStaff;
import com.yh.homestay.service.UserStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserStaffController
 * @Description 员工Controller
 * @Date 2020/1/13 18:35
 */
@RestController
@Api(description = "员工管理")
@RequestMapping(value = "/staff")
public class UserStaffController {

    @Autowired
    private UserStaffService userStaffService;

    /**
     * @param staffName
     * @param page
     * @param limit
     * @Date: 2020/1/14 17:55
     * @Description: 获取员工列表
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @SystemLog(methods = "员工信息列表", module = "员工管理")
    @ApiOperation(value = "获取员工列表", notes = "获取员工信息列表或者模糊查询数据")
    public HomeStayResult selectAll(String staffName, Integer page, Integer limit) {
        return userStaffService.showStaffs(page, limit, staffName);
    }

    /**
     * @param userStaff
     * @Date: 2020/1/14 17:55
     * @Description: 添加员工
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @SystemLog(methods = "添加员工", module = "员工管理")
    @ApiOperation(value = "添加员工", notes = "添加员工信息")
    public HomeStayResult addstaff(UserStaff userStaff) {
        return userStaffService.insertStaff(userStaff);
    }

    /**
     * @param id
     * @Date: 2020/1/14 17:55
     * @Description: 回显员工信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/one/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "回显员工信息", notes = "根据id回显员工信息")
    public HomeStayResult editstaff(@PathVariable("id") Integer id) {
        return userStaffService.showOneStaff(id);
    }

    /**
     * @param userStaff
     * @Date: 2020/1/14 17:56
     * @Description: 修改员工信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @SystemLog(methods = "修改员工信息", module = "员工管理")
    @ApiOperation(value = "修改员工信息", notes = "修改员工信息")
    public HomeStayResult editStaff(UserStaff userStaff) {
        return userStaffService.updateStaff(userStaff);
    }

    /**
     * @param staffId
     * @Date: 2020/1/14 17:56
     * @Description: 删除员工
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @SystemLog(methods = "删除员工", module = "员工管理")
    @ApiOperation(value = "删除员工", notes = "根据id删除员工")
    public HomeStayResult deleteById(Integer staffId) {
        return userStaffService.deleteStaff(staffId);
    }

    /**
     * @param ids
     * @Date: 2020/1/14 17:56
     * @Description: 批量删除员工
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @SystemLog(methods = "删除多个员工", module = "员工管理")
    @ApiOperation(value = "批量删除员工", notes = "根据ids批量删除员工")
    public HomeStayResult delectAll(@RequestParam("ids") List<Integer> ids) {
        return userStaffService.delectBatchStaff(ids);
    }
}
